is_leap_year = function(year){
	
	return ((year%%4==0)&&(year%%100!=0))||(year%%400==0)
}
convertJdayToDate=function(year,jday){
	if(is_leap_year(year)){
		day = c(1,32,61,92,122,153,183,214,245,275,306,336)
	}else{
		day = c(1,32,60,91,121,152,182,213,244,274,305,335)
	}
	for(i in(11:0)){
		if(jday-day[i]>=0){
			#date = paste(year,"-",i,"-",(jday+1-day[i]),sep="")
			date=i
			break
		}	
	}
	return(date)
}

inputPath= "C:/Users/forever/Desktop/BacTrungBo/"
fileArray = list.files(path = inputPath,pattern=".tif$",full.names = FALSE,recursive=TRUE)
totalFile = length(fileArray)
result = data.frame()

for(i in 1:totalFile){
	filename = fileArray[i]
	year = substr(fileArray[i],11,14)
	jday = substr(fileArray[i],15,17)
	month=convertJdayToDate(as.numeric(year),as.numeric(jday))
	result = rbind(result,data.frame(year,jday,month,filename))
}

write.csv(result,"C:/Users/forever/Desktop/BacTrungBo/list.csv")
